/*
业务员需求：
任务类型：设计预投申请 - 新建任务 √
表头【项目名称】—— 项目名称 √
需求明细【需求文件名称】—— 任务名称 √
【创建人】 —— 派发人 √
流程归档时间 —— 计划开始时间 ?
需求明细【需求时间】—— 计划完成时间 √
（电气助理、结构助理）抓电气、结构助理角色 —— 负责人 【要写api】
负责人领导 - 审批人 api

问题：
任务类型
执行人
负责人
* */

//单据

let num = $this.model.table_1753604068913_nGOJn.length;
if (num > 0) {
    for (let i = 0; i < num; i++) {
        let id = $this.$util.uuid(); // 表单id
        let no = $this.$util.uuid(); // 表单no
        let headData = $this.model; // 表头数据
        let bodyData = $this.model.table_1753604068913_nGOJn[i]; // 表体数据


        //任务名称字典匹配
        let tmpTaskName = bodyData["body_1753604090672_YIDVK"]
        switch (tmpTaskName) {
            case 'c8f425f8d594594593726086df320708':
                tmpTaskName = "所有资料都需要"
                break;
            case '1b52ce108f957fceee08fe0bd958bcef':
                tmpTaskName = "详见附件"
                break;
            case 'bd91c718ba7393c03a7adfd24ea1e33e':
                tmpTaskName = "0、图纸资料清单"
                break;
            case 'a569ab18a4cc98fb6d58c90153b29a09':
                tmpTaskName = "1、设备配置"
                break;
            case 'bbbe17661fe3f7a83dc25afff354053e':
                tmpTaskName = "2、消耗清单"
                break;
            case '389c1b5c3c32aafaf5cf017b65135bed':
                tmpTaskName = "3、接地及布置要求"
                break;
            case 'e5ff5ef7b55ce1f0f2af42471a22bbf9':
                tmpTaskName = "4、暖通要求"
                break;
            case '4fe8907d8964823ed8f3a98501dbe162':
                tmpTaskName = "5、变频器风道方案示意图"
                break;
            case '651451022007ae64cfaa7b0742a809d7':
                tmpTaskName = "6、变频器一次系统图"
                break;
            case 'cd7422896776156584b0a06842d471c0':
                tmpTaskName = "7、变频器对外电气接口图"
                break;

            case 'e3b0eb32e91355c2e2479f9da09e6f60':
                tmpTaskName = "8、变频器对外往来信号表"
                break;
            case '14f39542055127cbfc83ff67f12d1ac9':
                tmpTaskName = "9、变频器控制流程图"
                break;
            case 'db6a44bab7c9dab11aa5174ee1271199':
                tmpTaskName = "10、变频器对外动力电缆清单"
                break;
            case 'a188d9e557a1908eee63e666ca7c924d':
                tmpTaskName = "11、变频器对外控制电缆清单"
                break;
            case '0bab1854ab34b5468b04639a03bf0ac9':
                tmpTaskName = "12、变频器电气原理图"
                break;
            case 'a41d4d1b1a99d1526d42561cf6f9da4a':
                tmpTaskName = "13、变频器对外通讯地址表"
                break;
            case '4ccf400d6545397b0b0686bb9b1a4ae3':
                tmpTaskName = "14、变频器土建及安装要求、维护空间要求"
                break;
            case '78bef8344536d851804958ba8ac84d60':
                tmpTaskName = "15、变频器系统装置外形图"
                break;
            case '9b3d9a5e9b99f157b7b5fb015aec5d9f':
                tmpTaskName = "16、变频器系统装置基础图"
                break;
            case 'a6cd49673f6d63b1a6c90cce51bb7273':
                tmpTaskName = "17、变频器系统装置进出线孔图"
                break;
        }

//流程归档时间
        const d = new Date();
// ES2017 给字符串新增的左侧补全方法
        const pad = n => String(n).padStart(2, '0');
        const str = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
        console.log(str); // 2025-09-12 14:07:33
//负责人、负责人ID
        let userName = "";
        let userIds = "";
        let formData1 = new FormData()
        $this.$http.post('formsBusiness/getxmytRole', formData1)
            .then(res => {
                if (res.data.code === 280) {
                    let data = res.data.data;
                    userName = data['用户名s'];
                    userIds = data['用户名ids']

                    //负责人带出直属领导
                    let url = $this.$util.getAPI_URL();
                    let formData2=new FormData();
                    formData2.append("assigsId",userIds);
                    url = url.replace("api", "task/getTaskLeader");
                    $this.$http.post(url,formData2).then((res) => {
                        if(res.data.code===280){
                            console.log(res.data.data)
                            let data = res.data.data
                            let reviewerName = data.reviewerName;
                            let reviewerId = data.reviewerId;
                            if (data){
                                // $this.formModel["systemSelect_1711439400905_v5lzI"] = data.reviewerName
                                // $this.formModel["systemSelect_1711439400905_v5lzI_ID"] = data.reviewerId
                                //document.getElementById("systemSelect_1711439400905_v5lzI_ID").value = data.reviewerId

                                //流程归档时间
                                const time = new Date(bodyData["body_1753604094881_T4A0C"]);
                                // ES2017 给字符串新增的左侧补全方法
                                const pad = n => String(n).padStart(2, '0');
                                const t = `${time.getFullYear()}-${pad(time.getMonth() + 1)}-${pad(time.getDate())} ${pad(time.getHours())}:${pad(time.getMinutes())}:${pad(time.getSeconds())}`;
                                console.log(t); // 2025-09-12 14:07:33

                                let temp =
                                    `项目名称: ${headData.input_1753603734762_KB2ob}
                                    需求文件名称: ${tmpTaskName}
                                    需求时间: ${t}
                                    备注: ${bodyData["body_1753604097745_o0kOk"] || ''}`
                                ;

                                let saveObj = {
                                    "bill_id": id,
                                    "create_user_id": headData.create_user_id,
                                    "create_user_name": headData.create_user_name,
                                    "create_dept_name": headData.create_dept_name,
                                    "bill_type": headData.bill_type,
                                    "create_dept_id": headData.create_dept_id,
                                    "bill_no": no,
                                    "create_company_name": headData.create_company_name,
                                    "create_date": headData.create_date,
                                    "create_company_id": headData.create_company_id,
                                    //系统字段
                                    "number_1711439316655_41L04": 0,//计划工时
                                    "number_1711439319768_Hzhsj": 0,//文档数量
                                    "systemSelect_1711504973428_U0If2": headData.create_user_name,//派发人【创建人】 —— 派发人
                                    "systemSelect_1711504973428_U0If2_ID": headData.create_user_id,//派发人ID【创建人ID】派发人ID
                                    "number_1711505160101_Zy3nM": 0,//任务进度
                                    "number_1711505281945_eUZOr": 0,//里程碑序号
                                    "input_1711505283971_PgltR": "false",//里程碑
                                    "number_1711505313898_96ND4": "0",//任务累计工时
                                    "input_1711518795031_xvIfW": "1",//任务状态
                                    "systemSelect_1711520339026_rFF5K": headData.create_company_id,//派发部门
                                    "systemSelect_1711520339026_rFF5K_ID": headData.create_company_id,//派发部门id
                                    "select_1711505903223_YWk8w": "9d65629edb0dc87283d06fbd1572c69d",//任务类型:设计预投申请
                                    "input_1751171983502_E4gXx": 0,//计划项目编号
                                    //新建任务 - 设计预投申请【项目编号】
                                    "input_1718345101976_PBcTl": headData.input_1753603734762_KB2ob,//项目名称; 表头【项目名称】—— 项目名称
                                    "input_1711439260720_6QPqX": tmpTaskName,//任务名称; 需求明细【需求文件名称】—— 任务名称
                                    "rangePicker_1711439307444_Ftzhm": [str, bodyData["body_1753604094881_T4A0C"].format("YYYY-MM-DD HH:mm:ss")], //任务归档生成 - 【获取当前时间】归档日期
                                    "systemSelect_1711439400905_v5lzI": reviewerName,//审核人
                                    "systemSelect_1711439400905_v5lzI_ID": reviewerId,//审核人ID
                                    "systemSelect_1711439399614_qXQ72": userName, //userName = "李晓品(3220),蔡越(3214),陈蓉(3251),"//负责人
                                    "systemSelect_1711439399614_qXQ72_ID": userIds, //userIds = "953bc4d0f876a6cd69039f46bacc9038,811050ab9045bed93347b0f2d83ba285,8f8c137f15b37b666b41b89d89e076c2,"//负责人ID
                                    "input_1711520372633_i4sGc": headData.create_date,//派发时间
                                    "textarea_1755766219698_SuIuk":temp, //任务描述
                                }
                                let files = []
                                let formData = new FormData()
                                formData.append('obj', JSON.stringify(saveObj))
                                formData.append("files", JSON.stringify(files))
                                //save成功，表体task新建任务不成功？
                                $this.$http.post("/wind/form/save/" + "task" + "/" + "add", formData).then(res => {
                                    let data = res.data
                                    console.log(data)
                                }).catch(e => {
                                    $this.$message.error(e.message);
                                });
                            }
                        }
                    })

                } else {
                    $this.$message.error(res.data.msg ? res.data.msg : $this.$t('result.error.common.msg'));
                }
            })
            .catch(e => {
                $this.$message.error(e.message);
            });
    }
}